package com.briup.bookstore.service.impl;

import com.briup.bookstore.common.model.entity.Order;
import com.briup.bookstore.common.model.param.PageParam;
import com.briup.bookstore.dao.OrderDao;
import com.briup.bookstore.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class OrderServiceImpl implements OrderService {

    private final OrderDao orderDao;

    @Override
    public PageInfo<Order> pageQueryByClause(PageParam pageParam, Order orderParam) {
        /* 开始分页 */
        PageHelper.startPage(pageParam.pageNum(), pageParam.pageSize());
        /* 调用Dao层查询 */
        List<Order> books = orderDao.selectByClause(orderParam);
        /* 封装为分页对象 */
        return PageInfo.of(books);
    }

    @Override
    public void close(String id) {
        Order order = new Order()
                .setId(id)
                .setStatus(5);
        orderDao.updateSelective(order);
    }

    @Override
    public void delivery(Order orderParam) {
        orderParam.setStatus(3);
        System.out.println(orderParam);
        orderDao.updateSelective(orderParam);
    }

    @Override
    public Order getById(String id) {
        return orderDao.selectById(id);
    }


}
